<template>
	<div id="app" :style="{'width': width + 'px', 'height': height + 'px'}">
		<div class="container-box" :style="{'width': width + 'px', 'height': height + 'px'}">
            <router-view/>
			<router-view name="real"></router-view>
        </div>
	</div>
</template>

<script>
import * as types from "./config/postMessage-types";
import initTemplateConfig from "./helper/initTemplateConfig";
import "./helper/setEditConfig";//设置基于vue-prototype的便捷方法
export default {
	name: "App",
	data() {
		return {
			width: window.innerWidth,
			height:window.innerHeight,
			text: "正在定位……"
		};
	},
	methods: {
		sendMessageToWebView(msgObj) {
			// alert("这里在调用" + msgObj);
			// alert(window.postMessage);
			window.postMessage(JSON.stringify(msgObj));
		},
		// initSendMessageToWebView() {
		// 	PSEvent.listen("sendMessageToWebView", this.sendMessageToWebView);
		// },
		//初始化localForage
		// initLocalForage() {
		// 	let exits = document.body.querySelector("script[id=localforage]");
		// 	console.log("是否已经有localforage", exits);
		// 	if (exits) return;
		// 	let script = document.createElement("script");
		// 	script.setAttribute("id", "localforage");
		// 	script.onload = () => {
		// 		// PSEvent.trigger("")
		// 		// localforage.clear();
		// 	};
		// 	script.src = "static/script/lib/localForage.js";
		// 	document.body.appendChild(script);
		// },
		initLocalForage() {
			let script = document.createElement("script");
			script.onload = () => {
				// localforage.clear();
			};
			script.src = "static/script/lib/localForage.js";
			document.body.appendChild(script);
		},
		async initData() {
			let that = this
			console.log(location.hash,'location')
			if(navigator.userAgent.indexOf('xiangpu') > -1 && (location.hash == '#/' || location.hash == '#/main/home')) {
				console.log('测试一下')
				 cordova.exec(success, fail, "CommonPlugin", "getNotificationStatus", []);
				 console.log(success,'success88')
				 function success(res) {
					 console.log(res,'ress')
					 if(res==1) {
						that.hasNotice=true
						that.$store.commit('xxy/setNotice', true)
					 } else {
						that.hasNotice=false
						that.$store.commit('xxy/setNotice', false)
					 }
				 }
				 function fail(res) {
					console.log(res,'res')
				 }
			}

			if (
				this.sessionId === "null" ||
				this.sessionId === "undefined" ||
				!this.sessionId
			) {
				// this.ClEAR_SESSIONID("sessionId");
				// this.LOGO_OUT(false);
				// this.CLEAR_INFO(null);
				localStorage.setItem("chooseAddressActiveIndex", null);
				localStorage.setItem("locateIn", null);
				localStorage.setItem("locateOut", null);
				return;
			}
			//通过象谱账号登录后，再请求宁家账号的sessionId;
			let request = await accessLogin("eCode=" + api.enterpriseCode);
			if (request.status === 200) {
				if (request.data.data.returncode === 0) {
					Toast({
						message: request.data.data.msg,
						type: "warn",
						duration: api.alertTime_1
					});
					this.RECORD_SESSIONID(null);
					this.LOGO_IN(false);
					this.USER_INFO(null);
					localStorage.setItem("chooseAddressActiveIndex", null);
					localStorage.setItem("locateIn", null);
					localStorage.setItem("locateOut", null);
					return;
				} else {
					this.RECORD_SESSIONID(request.data.data[0]);
					this.LOGO_IN(true);
					this.USER_INFO(request.data.data[1].user);
					let that = this;
					if (navigator.userAgent.indexOf("xiangpu") > -1) {
						cordova.exec(
							success3,
							fail3,
							"CommonPlugin",
							"monitorLoginStatus",
							[]
						);
					}

					function success3(res) {
						that.ClEAR_SESSIONID("sessionId");
						that.LOGO_OUT(false);
						that.CLEAR_INFO(null);
						that.updateLocation(null);
						that.updateScopeOut(null);
						localStorage.setItem("chooseAddressActiveIndex", null);
						localStorage.setItem("locateIn", null);
						localStorage.setItem("locateOut", null);
						localStorage.setItem("cartArray", "");
						localStorage.setItem("cartFoodArray", "");
						localStorage.removeItem("sessionId", "");
						that.$store.dispatch("cjy/queryCart");
						that.setvuexPhoneNumber(null);
						that.setvuexPassword(null);
						that.setarrpopupnum([]);
						localStorage.setItem("phoneNumber", "");

						Toast({
							message: "您的帐号已在其他设备登录！",
							type: "warn",
							duration: 3000
						});
						that.$router.push({ path: "login" });
					}

					function fail3(res) {
						console.log(res, "resfail");
					}
				}
			} else {
				// Toast({
				// 		message:"网络错误！",
				// 		type:'warn',
				// 		duration: api.alertTime_1
				// 	})
				this.RECORD_SESSIONID(null);
				this.LOGO_IN(false);
				this.USER_INFO(null);
			}
		},
	},
	mounted() {
		// setTimeout(() => {
			// this.text = "定位成功";
			// this.sendMessageToWebView();
			// alert("postMessage.length" + postMessage.length);
			// let msgs = []
			let arr = [
				// {
				// 	type: types.EXIT_WEBVIEW
				// },
				{
					type: "ttt",
					params: {
						title: "测试ttt"
					}
				}
			];
			// postMessage(JSON.stringify(arr));
		// }, 2000);
		this.initLocalForage();
		setTimeout(() => {
			//页面初始化完毕，告诉RN可以初始化返回事件了
			this.sendMessageToWebView({
				type: types.INIT_BACKEVENT
			});
		}, 300);
	},
	created() {
		this.initData()
		//初始化模板参数信息
		// initTemplateConfig();
	}
};
</script>

<style>
#app {
	font-family: "Avenir", Helvetica, Arial, sans-serif;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	text-align: center;
	color: #2c3e50;
}
ol,
ul,
li {
	list-style: none;
	margin: 0;
	padding: 0;
}
body {
	margin: 0;
	width: 100%;
	height: 100%;
	background: #f5f5f5;
}
/* toast弹出框样式开始 */
.m-toast {
	background: rgba(255, 255, 255, 1);
	border-radius: 0.25rem;
	color: #000000;
	position: absolute;
	z-index: 999;
	top: 50%;
	left: 50%;
	box-shadow: 0 0 0.5rem rgba(0, 0, 0, 0.1);
	padding: 0.5rem 0.75rem;
	transform: translate(-50%, -40%);
	max-width: 9rem;
}
.m-toast i {
	font-size: 1.2rem;
}
.m-toast i.nj-tishi {
	color: #f29f00;
}
.m-toast i.nj-chenggong {
	color: green;
}
.m-toast i.nj-shibai {
	color: #c90000;
}
/* Toast的样式 */

.toast_warning {
	border: 2px solid #f0cb85;
}

.aui-toast {
	background: rgba(255, 255, 255, 1);
	text-align: center;
	border-radius: 0.25rem;
	color: #000000;
	position: absolute;
	z-index: 999;
	top: 45%;
	left: 50%;
	padding: 0.5rem 0 0.5rem 0.75rem;
	margin-left: -5em;
	box-shadow: 0 0 0.5rem rgba(0, 0, 0, 0.1);
	min-width: 7rem;
	line-height: 1;
	min-height: unset;
}

.aui-toast i.nj-tishi {
	color: #f29f00;
}

.aui-toast i.nj-chenggong {
	color: green;
}

.aui-toast i.nj-shibai {
	color: #c90000;
}

.toast_fail {
	border: 2px solid #ffb8b0;
}

.toast_success {
	border: 2px solid #a7d99d;
}

.aui-toast i {
	margin: 0 !important;
	padding: 0;
}

.aui-toast i {
	display: table-cell;
	font-size: 1.2rem;
	vertical-align: middle;
}

.njfont {
	font-size: 1rem;
	line-height: 1;
}

.njfont {
	font-family: "njfont" !important;
	font-style: normal;
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
}

.aui-toast-content {
	display: table-cell;
	font-size: 0.8rem;
	vertical-align: middle;
	padding: 0 0.4rem;
	min-width: 4.6rem;
}

.container-box .aui-mask.aui-mask-in {
	position: absolute !important;
}

.container-box .aui-dialog.aui-dialog-in {
	position: absolute !important;
	margin-left: 0px !important;
	left: 16% !important;
}

.box.outer-box {
	padding-top: 0px !important;
}
/* 全局菜单的样式 */

body .blooming-menu__container {
	/* left: 0; */
	left: unset;
	bottom: 10px;
	right: 15px;
	position: absolute;
	top: unset;
	transform: translate(0);
	line-height: unset;
}

body .blooming-menu__container .blooming-menu__main {
	line-height: unset;
	display: flex;
	justify-content: center;
	align-items: center;
}


body .blooming-menu__main-container .is-active {
	transform: rotate(90deg);
}

.blooming-menu__item-btn:hover {
	box-shadow: 0 8px 17px 0 rgba(0, 0, 0, 0.2);
	opacity: 1;
}

/*门店详情页地图的路径规划样式*/

.amap-call {
	display: none !important;
}
.poi-more {
	display: none;
}

.plan-nobus {
	max-height: 10rem;
	overflow-y: scroll;
}

/*门店详情页地图的路径规划样式*/
/* 商城快讯 v-html样式 */

.contentZx img {
	width: 100%;
}

/* 重置element-ui的级联框样式 */

/*解决我的消息富文本伪类样式问题*/
#app .m-message-list li p:after {
	display: none;
}

/* toast弹出框样式开始 */
.m-toast {
	background: rgba(255, 255, 255, 1);
	border-radius: 0.25rem;
	color: #000000;
	position: absolute;
	z-index: 999;
	top: 50%;
	left: 50%;
	box-shadow: 0 0 0.5rem rgba(0, 0, 0, 0.1);
	padding: 0.5rem 0.75rem;
	transform: translate(-50%, -40%);
	max-width: 9rem;
}

.m-toast i {
	font-size: 1.2rem;
}

.m-toast i.nj-tishi {
	color: #f29f00;
}

.m-toast i.nj-chenggong {
	color: green;
}

.m-toast i.nj-shibai {
	color: #c90000;
}
#app .aui-radio:checked,
#app .aui-radio.aui-checked,
#app .aui-checkbox:checked,
#app .aui-checkbox.aui-checked {
	background-color: #38b035;
}
.good_check .aui-radio:checked,
.good_check .aui-radio.aui-checked,
.good_check .aui-checkbox:checked,
.good_check .aui-checkbox.aui-checked {
	background-color: #38b035;
}
.green-style .aui-radio:checked,
.green-style .aui-radio.aui-checked,
.green-style .aui-checkbox:checked,
.green-style .aui-checkbox.aui-checked {
	background-color: #38b035;
}
#app .coupon_list li::after,
#app .coupon_list li::before {
	background-color: #fff;
}
/* 修改支付列表子项的高度 */
#app .aui-list-item {
	min-height: 2.5rem;
}
/* 覆盖protical样式 */
.proticalDetail h2,h3,h4,h5{
	text-align: left !important;
}
</style>
